$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        init:function () {
            this.form = new xhForm($('#xh_form'));
            this.form.parse();
            if (info) {
                this.form.fill(info);
            }
            $('[name=depId]').select2();
            this.listener();
        },
        listener:function () {
            var $this = this;

            //录用信息保存
            $('#save').click(function () {
                $this.funObj().submitForm()
            });

            $('#employ').click(function () {
                $this.funObj().employAction();
            })

        },
        funObj:function () {
            var $this = this;
            return {
                submitForm:function () {
                    $this.form.submit('hrm/staff_info/saveStaff',{},function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                    })
                },
                addForm:function (sTag) {
                    window.top.swal({
                        showCancelButton: true,
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        showLoaderOnConfirm: true,
                        allowOutsideClick: false,
                        title: '审批意见',
                        input: 'textarea',
                        preConfirm: function(explain) {
                            return new Promise(function (resolve, reject) {
                                if(!explain){
                                    reject('说明不能为空！');
                                }
                                else {
                                    resolve(explain);
                                }
                            })
                        }
                    }).then(function(explain) {
                        $this.funObj().saveExplain(sTag,explain);
                    }, function(dismiss) {});
                },
                editForm:function (iRAId, mDesc) {
                    window.top.swal({
                        showCancelButton: true,
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        showLoaderOnConfirm: true,
                        allowOutsideClick: false,
                        title: '审批意见',
                        inputValue:mDesc,
                        input: 'textarea',
                        preConfirm: function(explain) {
                            return new Promise(function (resolve, reject) {
                                if(!explain){
                                    reject('说明不能为空！');
                                }
                                else {
                                    resolve(explain);
                                }
                            })
                        }
                    }).then(function(explain) {
                        $this.funObj().saveExplain('',explain,iRAId);
                    }, function(dismiss) {});
                }
                // saveExplain:function (sTag,explain,iRAId) {
                //     var obj = {};
                //     obj.sType = 'employ';
                //     if (sTag) {
                //         obj.sVerifier = sTag;
                //     }
                //     obj.mDesc = explain;
                //     if (iRAId) {
                //         obj.iRAId = iRAId;
                //     }
                //     obj.iTargetId = sourceId;
                //     xhExtra.ajaxRequest('hrm/staff_info/saveApprove',obj,{},function (res) {
                //         window.top.xhTop.showSuccess(res.msg);
                //         location.reload();
                //     })
                // },
                // employAction:function () {
                //     window.top.swal({
                //         showCancelButton: true,
                //         confirmButtonText: '确认',
                //         cancelButtonText: '取消',
                //         showLoaderOnConfirm: true,
                //         allowOutsideClick: false,
                //         title: '发起入职',
                //         html:'<input id="date" class="form-control" type="date" placeholder="选择日期"><br>' +
                //         '<textarea id="desc" class="form-control" rows="3"></textarea>',
                //         preConfirm: function(explain) {
                //             return new Promise(function (resolve, reject) {
                //                 if(!explain){
                //                     reject('说明不能为空！');
                //                 }
                //                 else {
                //                     resolve(explain);
                //                 }
                //             })
                //         }
                //     }).then(function(explain) {
                //         // $this.funObj().saveExplain('',explain,iRAId);
                //     }, function(dismiss) {});
                // }
            }
        }
    }
};